//
//  ViewController.swift
//  2-07-OC网络
//
//  Created by 范英强 on 16/1/25.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //初始化url 并且保证有
        let url = NSURL(string: "http://www.weather.com.cn/data/sk/101010100.html")!
        //初始化reqest
        let requset = NSURLRequest(URL: url)
        //发送请求
        NSURLSession.sharedSession().dataTaskWithRequest(requset) { (data, _, _) -> Void in
            guard let d = data else{
                return
            }
            //序列化
            //try！ try？ try
            
//            let result = try? NSJSONSerialization.JSONObjectWithData(d, options: [])
//            print(result)
            
            do {
                let result = try NSJSONSerialization.JSONObjectWithData(d, options: [])
                print(result)
            }catch{
                print(error)
            }
        }.resume()
        
    }

    


}

